<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首付款管理 新增</title>
<jsp:include page="../../import.jsp" flush="true" />
<style type="text/css">
	.sq-formTable .field {
			width: 80px;
	}
</style>
</head>
<body class="iframeBody">
	<div class="Wrapper">
	<form id="fncPrjFstpyInfo_form" class="pageInTab">
		<div class="fieldset1 tabel_col tabel_col_1 clearFix">

			<div class="fieldBox col_33">
				<div class="label">项目名称：</div>
				<div class="field">
					<input name="fncPrjNm" id="fncPrjNm" type="text" class="ui-textbox" value="" disabled="disabled">
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">项目编号：</div>
				<div class="field">
					<input name="fncPrjIdStr" id="fncPrjIdStr" type="text" class="ui-textbox" value="" disabled="disabled">
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">创建时间：</div>
				<div class="field">
					<input name="crtTm" id="crtTm" type="text" class="ui-textbox" value="" disabled="disabled">
				</div>
			</div>

			<div class="fieldBox col_33">
				<div class="label">融资机构：</div>
				<div class="field">
					<input name="fundRasInsNm" id="fundRasInsNm" type="text" class="ui-textbox" value="" disabled="disabled">
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">融资报价：</div>
				<div class="field">
					<input name="fncScmNm" id="fncScmNm" type="text" class="ui-textbox" value="" disabled="disabled">
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">计划融资金额：</div>
				<div class="field">
					<input name="fncFiAmt" id="fncFiAmt" type="text" class="ui-textbox" value="" disabled="disabled">
				</div>
			</div>

			<div class="fieldBox col_33">
				<div class="label">项目金额：</div>
				<div class="field">
					<input name="fncPrjAmt" id="fncPrjAmt" type="text" class="ui-textbox" value="" disabled="disabled">
				</div>
			</div>

			<div class="fieldBox col_33">
				<div class="label">支付表数量：</div>
				<div class="field">
					<input name="payCnt" id="payCnt" type="text" class="ui-textbox" value="" disabled="disabled">
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">实际融资金额：</div>
				<div class="field">
					<input name="acFiAmt" id="acFiAmt"  type="text" class="ui-textbox" value="" onchange="changeAmt(this.value)" validate="{number:true,required:true}">
					<span class="requiredSymbol">*</span>
					
				</div>
			</div>
			
			<!-- hide data -->
			<div class="fieldBox col_100" style="display:none;">
				<div class="field">
					<input name="dataId" id="dataId" type="text" class="ui-textbox" value="${fncPrjId}">
					<input name="fncInsId" id="fncInsId" type="text" class="ui-textbox" value="${fncInsId}">
				</div>
			</div>

		</div>

	<!-- 	<div class="fieldset1 tabel_col tabel_col_s clearFix">
			<div class="caption">
				<span class="title">账户信息</span>
			</div>
			<div class="fieldBox col_50">
				<div class="label">机构收款账户</div>
				<div class="field">
					<input name="fstpyAccno" id="fstpyAccno" type="text" class="ui-textbox" value="" validate="{required:true}">
					<span class="requiredSymbol">*</span>
				</div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">我司付款账户</div>
				<div class="field">
					<input name="fstpyPayAccno" id="fstpyPayAccno" type="text" class="ui-textbox" value="" validate="{required:true}">
					<span class="requiredSymbol">*</span>
				</div>
			</div>
		</div> -->

		<div class="fieldset1 tabel_col tabel_col_s clearFix">
			<div class="caption">
				<span class="title">首付款信息</span>
			</div>
			<div class="fieldBox col_100" style="display:none;">
			</div>
			<div style="width:1100px; overflow:auto;">
			<!-- <table id="fstpyTable" class="sq-formTable">
				<tbody>
					<tr>
						<td style="padding: 0;text-align: center;"> -->
							<table id="tableMain" class="sq-formTable no-border">
								<thead>
									<tr>
										<th class="tbLabel" style="text-align: center;"><div class="field" >费用名称</div></th>
										<th class="tbLabel" style="text-align: center;"><div class="field" >费用比例（%）</div></th>
										<th class="tbLabel" style="text-align: center;"><div class="field" >费用基数</div></th>
										<th class="tbLabel" style="text-align: center;"><div class="field" >是否坐扣</div></th>
										<th class="tbLabel" style="text-align: center;"><div class="field" >费用金额</div></th>
										<th class="tbLabel" style="text-align: center;"><div class="field" >实际费用金额</div></th>
										<!-- <th class="tbLabel" style="text-align: center;"><div class="field" >保证金是否已付</div></th> -->
										<th class="tbLabel" style="text-align: center;"><div class="field" >关联保证金的项目</div></th>
										<th class="tbLabel" style="text-align: center;"><div class="field" >计划退回时间</div></th>
										<th class="tbLabel" style="text-align: center;"><div class="field" >机构收款账户</div></th>
										<th class="tbLabel" style="text-align: center;"><div class="field" >我司付款账户</div></th>
										<th class="tbLabel" style="text-align: center;"><div class="field" >备注</div></th>
									</tr>
								</thead>
								<tbody>
									<tr id="totalTr">
										<td style="text-align: right;" colspan="4">合计：</td>
										<td style="text-align: center;">
											<span name="totalCost" >
										</td>
										<td style="text-align: center;" >
											<input name="totalPay" type="text" disabled="disabled">
										</td>
										<td style="text-align: center;" colspan="5"></td>
										
									</tr>
								</tbody>
							</table>
					<!-- 	</td>
					</tr>
				</tbody>
			</table> -->
			</div>
		</div>
		
		<div class="btnsBox">
		
			<c:if test="${mgrUpdateNode}">
				<!-- 来自再融资首付款流程-融资经理修改节点,只需要保存数据 -->
				<span id="cr_bsc_info_add_btn_id" class="sq-button sq-button-round" onclick="save();">保存 </span>
			</c:if>
			<c:if test="${!mgrUpdateNode}">
				<!-- 先保存数据,然后发起流程 -->
				<span id="cr_bsc_info_add_btn_id" class="sq-button sq-button-round" onclick="save();">申请付款 </span>
			</c:if>
			
		</div>
	</form>
	</div>
	<script type="text/javascript">
		
		$(function() {
			
			//initPayList();
			$("#fncPrjFstpyInfo_form").ligerForm({
				validate : true
			});
			initData();
			
		});

		//保存
		function save() {
			var ligerForm = liger.get("fncPrjFstpyInfo_form");
			if (!ligerForm.valid()) {
				UIUtils.alertWarning("有验证信息未通过!");
				return false; //验证不通过，不执行以下代码
			}
			var data = ligerForm.getData();
			var dataId = $("#dataId").val();
			
			var url = '<%=path%>/rfbase/fncprjfstpyinfo/add.do';
            if(StringUtils.isNotEmpty(dataId)){
            	url = '<%=path%>/rfbase/fncprjfstpyinfo/modify.do';
            	data["fncPrjId"]= dataId;
            }
			
            data["acFiAmt"] = $("#acFiAmt").ligerGetTextBoxManager().getValue();
            
            //首付款信息
			var fstpyArray = [];
			var fstpyTr = $('#tableMain tbody tr');
			
			for (var i = 0; i < fstpyTr.length - 1; i++) {
				var costAmt = $.trim($(fstpyTr[i]).find("span[name='costAmt']").text().replace(/,/g,""));
				var payAmt = $.trim($(fstpyTr[i]).find("input[name='payAmt']").val().replace(/,/g,""));
				var rmrk = $.trim($(fstpyTr[i]).find("input[name='rmrk']").val());
				
				if( Number(payAmt) != Number(costAmt) && (rmrk == ""|| rmrk == null)){
					$(fstpyTr[i]).find("input[name='rmrk']").addClass('errorRequried');
				}else{
					$(fstpyTr[i]).find("input[name='rmrk']").removeClass('errorRequried');
				}							
			}
			
			for (var i = 0; i < fstpyTr.length - 1; i++) {
				var id = $.trim($(fstpyTr[i]).find("input[name='id']").val());
				var scmChrgId = $.trim($(fstpyTr[i]).find("input[name='scmChrgId']").val());
				var mrgnIs = $.trim($(fstpyTr[i]).find("input[name='mrgnIs']").val());
				var wthrDdct = $.trim($(fstpyTr[i]).find("span[name='wthrDdct']").text().replace(/,/g,""));
				var costNm = $.trim($(fstpyTr[i]).find("span[name='costNm']").text());
				var costAmt = $.trim($(fstpyTr[i]).find("span[name='costAmt']").text().replace(/,/g,""));
				var payAmt = $.trim($(fstpyTr[i]).find("input[name='payAmt']").val().replace(/,/g,""));
				var recAccount = $("#recAccount"+i).ligerComboBox().getValue();
				var payAccount = $("#payAccount"+i).ligerComboBox().getValue();
				var rmrk = $.trim($(fstpyTr[i]).find("input[name='rmrk']").val());
				var isAlreadyPay = $("#isAlreadyPay"+i).val();
				var whichPrjId = $("#whichPrjId"+i).val();
				var reReturnTm = $("#reReturnTm"+i).val();
				
				if(Number(payAmt) < 0){
					UIUtils.alertWarning("实际费用金额不能为负数!");
					return false;
				}
				if(!recAccount){
					UIUtils.alertWarning("请选择机构收款账户,行号："+(i+1));
					return false;
				}
				if(!payAccount){
					UIUtils.alertWarning("请选择我司付款账户,行号："+(i+1));
					return false;
				}
				if( Number(payAmt) != Number(costAmt) && (rmrk == ""|| rmrk == null)){
					UIUtils.alertWarning("有备注信息未填写!");
					return false;
				}
				
				if(mrgnIs ==1) {
					if(wthrDdct == "默认已付" && !whichPrjId){
						UIUtils.alertWarning("请选择关联保证金的项目,行号："+(i+1));
						return false;
					}
				}
				
				
				var fstpy = {
					"id" : id,
					"scmChrgId" : scmChrgId,
					"mrgnIs" : mrgnIs,
					"fncPrjId" : data.fncPrjId,
					"costNm" : costNm,
					"costAmt" : costAmt,
					"payAmt" : payAmt,
					"recAccount" : recAccount,
					"payAccount" : payAccount,
					"isAlreadyPay" : isAlreadyPay,
					"whichPrjId" : whichPrjId,
					"reReturnTm" : reReturnTm,
					"rmrk" : rmrk
				}
				fstpyArray.push(fstpy);
			}
			data["fstpyArray"] = JSON.stringify(fstpyArray);
			data["totalPay"]= $("input[name='totalPay']").val().replace(/,/g,"");
			if(Number(data["totalPay"]) < 0){
				UIUtils.alertWarning("实际费用金额合计不能为负数!");
				return false;
			}else if(Number(data["totalPay"]) > Number($('#acFiAmt').val())){
				UIUtils.alertWarning("“实际费用金额”合计 不能大于 “实际融资金额”!");
				return false;
			}
			
			console.log(data);
			//return;
			AjaxUtils.ajaxPost(url, data, addCallback);
		}
		
		//新增回调
		function addCallback(msg) {
			if (msg.success == 1) {
				// frameElement.dialog.close();
				/* var selectedTabId = parent.mainApp.parentTab.selectedTabId;
				 var lastTab = parent.tabItems[0];
				 parent.mainApp.parentTab.reload(lastTab.tabid);
				 parent.mainApp.parentTab.removeTabItem(selectedTabId);
				 parent.grid.reload(); */
				 
				 var mgrUpdateNode = "${mgrUpdateNode}";
				 if("true" == mgrUpdateNode) {
					 UIUtils.alertSuccess("保存成功");
				 }else {
					 //发起首付款流程
					 startFlow($("#dataId").val());
				 }
			} else {
				UIUtils.alertError(msg.info);
			}
		}

		//发起审核流程
		function startFlow(_id){
			if(!_id)return;
			var modelTyp ="R014";//流程业务分类-再融资首付款审核
		//	alert(modelTyp);
			if(StringUtils.isEmpty(modelTyp)){
				console.log("modelTyp is null");
				return;
			}
	        var flowDialog = $.ligerDialog.SQopen({
	            url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp='+modelTyp,
	            width: 700,
	            height:400,
	            title : '请选择要发起的流程',
	            buttons: [{
		                text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
		                onclick: function (item, Dialog) {
		                    if (Dialog.onOk) Dialog.onOk();
		                }
		            }, {
		                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
		                onclick: function (item, Dialog) {
		                    if (Dialog.onCancel) Dialog.onCancel();
		                }
		            }
		        ],
	            onClose: function () {
	            	var json = flowDialog._DATA;
	            	console.log(json);
	            	if(!json){
	                	return;
	            	}
	            	var wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
	        		$.ajax({
	            		type: 'post',
	            		dataType:'json',
	            		data:{
	            			fncPrjId:_id,
	            			procDefKey:json.procDefKey,
	            			procDefId:json.procDefId,
	            			procNo:json.procNo
	            		},
	            		url: '<%=path%>/rfbase/fncprjfstpyinfo/addFlowStart.do',
	            		success:function(msg){
	            			wait_dialog.close();
	            			 if(msg.success == 1){
	          					 UIUtils.alertSuccessHold1(msg.info);
	           				 	 //grid.reload();
	           				 	 //alert(1);
	           				 	$("#cr_bsc_info_add_btn_id").hide();
		           			 }else{
		          				UIUtils.alertErrorHold1(msg.info);
		           			 }
	            		}
	            	});
	            }
	        });
		}	
		 
		//修改初始化数据
		function initData() {
			var dataId = $("#dataId").val();
			if (StringUtils.isEmpty(dataId))
				return;
			var _url = '<%=path%>/rfbase/fncprjfstpyinfo/getById.do';
			var wthrDdctFstPay = '0,2'; // 不坐扣、默认已付
			AjaxUtils.ajaxGet(_url, {
				fncPrjId : dataId,
				wthrDdctFstPay : wthrDdctFstPay
			}, initCallback);
		}

		//初始化回调
		function initCallback(msg) {
			if (msg.success == 1) {
				setData(msg.data);//设置数据
				
				
				
			} else {
				UIUtils.alertError(msg.info);
			}
		}

		//修改时候设置页面数据
		function setData(data) {
			var form = new liger.get("fncPrjFstpyInfo_form");
			
			$("#acFiAmt").ligerGetTextBoxManager().setValue(data.acFiAmt);
			$("#acFiAmt").ligerTextBox({ nullText: '请填写', currency: true });
			
			form.setData({
				fncPrjIdStr : data.fncPrjIdStr,
				fncPrjNm : data.fncPrjNm,
				crtTm : renderDate(data.crtTm),
				fundRasInsNm : data.fundRasInsNm,
				fncScmNm : data.fncScmNm,
				fncPrjAmt : formatMoney(data.fncPrjAmt),
				fncFiAmt : formatMoney(data.fncFiAmt),
				payCnt : data.payCnt,
			});
			
			/* form.setData({
				fstpyAccno : data.fstpyAccno,
				fstpyPayAccno : data.fstpyPayAccno,
			}); */
			
			//首付款信息
			var fstpyVos = data.fncPrjFstpyInfoVOs;
			for (var i = 0; i < fstpyVos.length; i++) {
				addRow(i,fstpyVos[i],data);
				//设置默认值
				console.log(fstpyVos[i].isAlreadyPay);
				$("#isAlreadyPay"+i).val(fstpyVos[i].isAlreadyPay);
				$("#whichPrjId"+i).val(fstpyVos[i].whichPrjId);
				$("#reReturnTm"+i).val(renderDate(fstpyVos[i].reReturnTm));
				
				var tr = $('#tableMain tbody tr:eq('+i+')');
				if(fstpyVos[i].costPct== '' || null ==fstpyVos[i].costPct || fstpyVos[i].costPct == 0){
					fstpyVos[i].costPct = '--';
					fstpyVos[i].costCrdnltNm = '--';
					if(fstpyVos[i].costPct== '' || null == fstpyVos[i].costAmt || fstpyVos[i].costPct == 0){
						fstpyVos[i].costAmt = fstpyVos[i].fscpCostAmt;
					}
				}else{
					/* 百分比显示 */
					fstpyVos[i].costPct = accMul(fstpyVos[i].costPct,100);
					fstpyVos[i].costCrdnltNm = "融资金额";
				}
				tr.find("span[name='costNm']").html(fstpyVos[i].costNm);
				tr.find("span[name='costPct']").html(fstpyVos[i].costPct);
				tr.find("span[name='costCrdnltNm']").html(fstpyVos[i].costCrdnltNm);
				tr.find("span[name='wthrDdct']").html(renderYesNo(fstpyVos[i].wthrDdct,fstpyVos[i].mrgnIs));
				tr.find("span[name='costAmt']").html(fstpyVos[i].costAmt);
				tr.find("input[name='payAmt']").val(fstpyVos[i].payAmt);
				
				tr.find("input[name='id']").val(fstpyVos[i].id);
				tr.find("input[name='scmChrgId']").val(fstpyVos[i].scmChrgId);
				tr.find("input[name='mrgnIs']").val(fstpyVos[i].mrgnIs);
				tr.find("input[name='rmrk']").val(fstpyVos[i].rmrk);
				
				 //显示机构收款账户、我司付款账户 明细的下拉选项
				 initRecvList(i,fstpyVos[i].recAccount);
				 initPayList(i,fstpyVos[i].payAccount);
					
			}
			
			var acFiAmt=$('#acFiAmt').val();
			if(acFiAmt==""){acFiAmt=0;}
			 changeAmt(acFiAmt,data.acFiAmt);
			 //初始化显示
			 if(data.acFiAmt != null){
			 	$("#acFiAmt").val(formatMoney(data.acFiAmt));
			 }
			 
		};
		
		function addRow(i,fstpyVo,data){
			
			 var trHtml='<tr>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="costNm" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="costPct" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="costCrdnltNm" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="wthrDdct" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="costAmt" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field" style="width: 130px;">'+
						 '<input name="payAmt" type="text" value="" onchange="setTotal()">'+
					'</div>'+
				'</td>';
				
				trHtml = trHtml +
				'<td style="text-align: center;">';
				if(fstpyVo.mrgnIs == 1 && fstpyVo.wthrDdct ==2) {//默认已付的保证金，需要加上 <关联保证金的项目>
				
					trHtml = trHtml +
					'<div class="field" style="width: 150px;">'+
							'<select id="whichPrjId'+i+'" name="whichPrjId" style="width: 150px;">'+
									'<option value ="">请选择</option>'+
								 <c:forEach items="${fncPrjBscInfoVOList }" var="vo">
									 '<option value ="${vo.id}">${vo.fncprjnm}</option>'+
		                        </c:forEach>
							'</select>'+
					'</div>';
				}
				
				trHtml = trHtml +'</td><td style="text-align: center;">';
				if(fstpyVo.mrgnIs == 1 ) {//如果是保证金，需要加上计划退回时间
				
					trHtml = trHtml +
					'<div class="field" style="width: 150px;">'+
							'<input name="reReturnTm" id="reReturnTm'+i+'"  type="text"  value="" >'+
					'</div>';
				}
				
				trHtml = trHtml +
				'</td>'+
				'<td style="text-align: center;">'+
				'<div class="field" style="width: 200px;">'+
					 '<input id="recAccount'+i+'" name="recAccount" type="text" class="ui-textbox" value="" validate="{required:true}">'+
				'</div></td>'+
				'<td style="text-align: center;">'+
				'<div class="field" style="width: 200px;">'+
					 '<input id="payAccount'+i+'" name="payAccount" type="text" class="ui-textbox" value="" validate="{required:true}">'+
				'</div>'+
			'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field" style="width: 130px;">'+
					   '<input name="rmrk" type="text" >'+
					   '<input name="id" type="hidden" value="" >'+
					   '<input name="scmChrgId" type="hidden" value="" >'+
					   '<input name="mrgnIs" type="hidden" value="" >'+
					'</div>'+
				'</td>'+
			'</tr>';

			$('#totalTr').before(trHtml);
			
			$("#reReturnTm"+i).ligerDateEditor({  labelWidth: 100, labelAlign: 'left' });
		}
		
		function changeAmt(val,dataAcFiAmt){
			var fstpyTr = $('#tableMain tbody tr');
			for (var i = 0; i < fstpyTr.length - 1; i++) {
				var amt = 0;
				var costPct = $.trim($(fstpyTr[i]).find("span[name='costPct']").text());
				var costAmt = $.trim($(fstpyTr[i]).find("span[name='costAmt']").text().replace(/,/g,""));
				if(costPct != '--'){
					amt = accMul(val,accMul(costPct,0.01));
				}else{
					amt = costAmt;
				}
				$(fstpyTr[i]).find("span[name='costAmt']").html(formatMoney(amt, 2));
				if(val != dataAcFiAmt){
					
				$(fstpyTr[i]).find("input[name='payAmt']").val(formatMoney(amt, 2));
				}
				$(fstpyTr[i]).find("input[name='payAmt']").ligerTextBox({ nullText: '请填写', currency: true });
			}
			
			setTotal();
		}
		
		function setTotal(){
			var totalPayAmt =0;
			var totalCostAmt = 0;
			var fstpyTr = $('#tableMain tbody tr');
			for (var i = 0; i < fstpyTr.length - 1; i++) {
				var costAmt = $(fstpyTr[i]).find("span[name='costAmt']").text().replace(/,/g,"");
				var payAmt = $(fstpyTr[i]).find("input[name='payAmt']").val().replace(/,/g,"");
				if($.trim(costAmt)==''||null == costAmt){
					costAmt = 0;
				}
				if($.trim(payAmt)==''||null == payAmt){
					payAmt = 0;
				}
				totalCostAmt = accAdd(totalCostAmt,costAmt);
				totalPayAmt = accAdd(totalPayAmt,payAmt);
			}
			$('#totalTr').find("span[name='totalCost']").html(formatMoney(totalCostAmt,2));
			$('#totalTr').find("input[name='totalPay']").val(formatMoney(totalPayAmt,2));
		}
		
/* 		function changeRmrkSt(ele){
			var parentTr = $(ele).parent().parent().parent();
			var costAmt = parentTr.find("input[name='costAmt']").val().trim();
			var payAmt = ele.value.trim();
			var rmrk = parentTr.find("input[name='rmrk']");
			if( payAmt != costAmt && rmrk.val().trim() == ""){
				rmrk.addClass('errorRequried');
				rmrk.focus();
			}else{
				rmrk.removeClass('errorRequried');
			}
		} */
		
		function changeAcFiAmt(ele){
			var  moneyNum = ele.value.trim();
			var moneyStr = formatMoney(moneyNum);
			$(ele).val(moneyStr);
			$(ele).parent().siblings("input[type='hidden']").val(moneyNum);
			
			changeAmt(moneyNum);
		}
		
		function setTotalView(ele){
			var  moneyNum = ele.value.trim();
			var moneyStr = formatMoney(moneyNum);
			$(ele).val(moneyStr);
			$(ele).siblings("input[type='hidden']").val(moneyNum);
			
			setTotal();
		}
		
		//数字格式转换成千分位
		function formatMoney(number, places, symbol, thousand, decimal) {
			number = number || 0;
			places = !isNaN(places = Math.abs(places)) ? places : 2;
			// symbol = symbol !== undefined ? symbol : "$";
			symbol = symbol !== undefined ? symbol : "";
			thousand = thousand || ",";
			decimal = decimal || ".";
			var negative = number < 0 ? "-" : "", 
				i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10)+ "",
				j = (j = i.length) > 3 ? j % 3 : 0;
			return symbol
					+ negative
					+ (j ? i.substr(0, j) + thousand : "")
					+ i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand)
					+ (places ? decimal
					+ Math.abs(number - i).toFixed(places).slice(2) : "");
		}
		
		//格式化时间
		 function renderDate(value){
			var dateStr = "";
			if(null != value &&  ""!= value){
				var date = new Date(value);
				dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
			}
			return dateStr;
		 }
		
		//显示是否
		function renderYesNo(value,mrgnIs){
			var dateStr = "";
			if(0 == value){
				dateStr = "否";
			}
			if(1 == value){
				dateStr = "是";
			}
			if(2 == value){
				if(mrgnIs==1) {
					dateStr = "默认已付";
				}else {
					dateStr = "是/否";	
				}
				
			}
			return dateStr;
		}
		
	    function initRecvList(i,recAccount){
	   	   var instid = $("#fncInsId").val();
	   	   $("#recAccount"+i).ligerComboBox({
	             columns: [
	 	                { header: '开户行号', name: 'banAccNum', width: 100}, 
	 	                { header: '开户行名', name: 'banAccNm', width: 100}, 
	 	                { header: '账户名称', name: 'accNm', width: 120},
	 	                { header: '账号', name: 'accNum', width: 120},
	 	               ],
	 	            url:'<%=path%>/rfbase/fncprjfstpyinfo/initRecvList.do?insId='+instid,
	 	            ajaxType :'GET',
	 	            width: 200, slide: false,
	 	            selectBoxWidth: 680, selectBoxHeight: 240,
	 	            valueField: 'id', textField: 'accNum',
	 	           initValue: recAccount 
	 	       });
	   	
	      }
	     function initPayList(i,payAccount){
	   	   var instid = $("#fncInsId").val();
	   	   $("#payAccount"+i).ligerComboBox({
	             columns: [
	 	                { header: '开户行号', name: 'bkId', width: 100}, 
	 	                { header: '开户行名', name: 'bkNm', width: 100}, 
	 	                { header: '账户名称', name: 'accNm', width: 120},
	 	                { header: '账号', name: 'accNo', width: 120},
	 	               ],
	 	            url:'<%=path%>/rfbase/fncprjfstpyinfo/initPayList.do?insId='+instid,
	 	            ajaxType :'GET',
	 	            width: 200, slide: false,
	 	            selectBoxWidth: 680, selectBoxHeight: 240,
	 	            valueField: 'id', textField: 'accNo',
	 	           initValue: payAccount 	            
	 	       });
	     }
 
	     
	   //js 加法计算  
	   //调用：accAdd(arg1,arg2)  
	   //返回值：arg1加arg2的精确结果   
	   function accAdd(arg1,arg2){   
	     var r1,r2,m;   
	     try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}   
	     try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}   
	     m=Math.pow(10,Math.max(r1,r2))   
	     //return ((arg1*m+arg2*m)/m).toFixed(2);   
	     return ((arg1*m+arg2*m)/m); 
	   }   
	   //js 减法计算  
	   //调用：Subtr(arg1,arg2)  
	   //返回值：arg1减arg2的精确结果   
	   function Subtr(arg1,arg2){  
	        var r1,r2,m,n;  
	        try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}  
	        try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}  
	        m=Math.pow(10,Math.max(r1,r2));  
	        //last modify by deeka  
	        //动态控制精度长度  
	        n=(r1>=r2)?r1:r2;  
	        return ((arg1*m-arg2*m)/m).toFixed(2);  
	   }   
	   //js 除法函数  
	   //调用：accDiv(arg1,arg2)  
	   //返回值：arg1除以arg2的精确结果   
	   function accDiv(arg1,arg2){   
	     var t1=0,t2=0,r1,r2;   
	     try{t1=arg1.toString().split(".")[1].length}catch(e){}   
	     try{t2=arg2.toString().split(".")[1].length}catch(e){}   
	     with(Math){   
	       r1=Number(arg1.toString().replace(".",""))   
	       r2=Number(arg2.toString().replace(".",""))   
	       return (r1/r2)*pow(10,t2-t1);   
	     }   
	   }   
	     
	   //js 乘法函数  
	   //调用：accMul(arg1,arg2)   
	   //返回值：arg1乘以arg2的精确结果   
	   function accMul(arg1,arg2)   
	   {   
	     var m=0,s1=arg1.toString(),s2=arg2.toString();   
	     try{m+=s1.split(".")[1].length}catch(e){}   
	     try{m+=s2.split(".")[1].length}catch(e){}   
	     return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)   
	   }   

	</script>
	<style type="text/css">
		.errorRequried{
			border:1px solid red;
		}
	</style>
</body>
</html>